<?
	$_SESSION['url'] = getURL();
	if($_SESSION['is_login'] != true){
		header("Location: ".$root."/dang-nhap/");
	}
	
	if(isset($_POST['submit'])){
		$t_tieude = addslashes($_POST['t_tieude']);
		$t_mota = addslashes($_POST['t_mota']);
		$t_loaisanpham = $_POST['t_loaisanpham'];
		$t_nguoidang = $_SESSION['uid'];
		//Hinhanh
		$DuongDanAnh = $upload->upload_file($PathFile,'t_hinhanh');
		if($DuongDanAnh != ""){
			$filetype = $upload->file_type($DuongDanAnh);
			$upload->crop_image($imgWidth,$imgHeight,$PathFile . $DuongDanAnh,$filetype,$PathThumbFile .$DuongDanAnh);
		}
		//
		$t_giaban = addslashes($_POST['t_giaban']);
		$t_loaitien = $_POST['t_loaitien'];
		$t_giathitruong = $_POST['t_giathitruong'];
		$t_loaitien_giathitruong = $_POST['t_loaitien_giathitruong'];
		$txtQuocGia = $_POST['txtQuocGia'];
		$txtTinhThanh = $_POST['txtTinhThanh'];
		$chkPhuongThucBan = $_POST['chkPhuongThucBan'];
		$t_noibat = $_POST['t_noibat'];
		$t_sapramat = $_POST['t_sapramat'];
		$t_khuyenmai = $_POST['t_khuyenmai'];
		$t_chitiet = addslashes($_POST['t_chitiet']);
		
		
		$insert = "INSERT INTO ".$prefix."sanpham(`t_loaisanpham`, `t_nguoidang`, `t_tieude`, `t_hinhanh`, `t_mota`, `t_giaban`,`t_giathitruong`, `t_loaitien`, `t_loaitien_giathitruong`, `t_quocgia`, `t_tinhthanh`, `t_ngaydang`, `t_chitiet`, `t_phuongthucban`, `t_solanxem`, `t_noibat`, `t_khuyenmai`, `t_sapramat`, `t_hienthi`) VALUES('".$t_loaisanpham."','".$t_nguoidang."','".$t_tieude."','".$DuongDanAnh."','".$t_mota."','".$t_giaban."', '".$t_giathitruong."', '".$t_loaitien."', '".$t_loaitien_giathitruong."', '".$txtQuocGia."','".$txtTinhThanh."',now(),'".$t_chitiet."','".$chkPhuongThucBan."',0,'".$t_noibat."', '".$t_khuyenmai."', '".$t_sapramat."', 1)";
		//echo $insert;
		$db->query($insert);
		//Lay Id
		$rs = $db->query("SELECT * FROM ".$prefix."sanpham WHERE t_hienthi = 1 ORDER BY t_id DESC LIMIT 1");
		$row = $db->fetch_array($rs);
		$pid = $row[t_id];
		header("Location: ".$root."/chi-tiet-san-pham/".$pid."/".$myString->vietdecode(loadSanPham($pid))."");
	}
?>
<div id="linkPath">
 
 <script language="javascript" type="text/javascript">
    function CheckVND()
    {
        if(document.getElementById("chkVND").checked==true)
        {
            document.getElementById("btnSave").style.display='';
            document.getElementById("btnSave_off").style.display='none';
        }
        else
        {
            document.getElementById("btnSave").style.display='none';
            document.getElementById("btnSave_off").style.display='';
        }
    }
</script>
       

<div class="linkPath">
    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>

    </div>
    <div class="corner-round-01-body">    
        <span style="float: left;"><a href="<?=$root?>/trang-chu/">Trang chủ</a> &raquo; Đăng bán</span>
        <span style="float: right;"><a title="Quay lại trang trước" class="link-back" href="javascript:void(0);" onclick="javascript:history.go(-1);">Quay lại</a></span>
        <div style="clear: both;"></div>
    </div>
    <div class="corner-round-01-bottom-right">

        <div class="corner-round-01-bottom-left">
            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>    
    </div>

<form action="" name="frmDangBan" id="frmDangBan" method="post" enctype="multipart/form-data" onsubmit="return funDangBanChecker();">
    <!-- Main Page-Content { -->    
    <div id="page-content">                            
        
<div id="product-new">
    <div class="corner-round-02-top-right">

        <div class="corner-round-02-top-left">
            <div class="corner-round-02-top-bg"></div>
        </div>
    </div>
    <div class="corner-round-02-body" style="height:auto;overflow:hidden">            
        <div id="error" class="form-error-group" style="none: block;width:816px">            
        </div>
        <div class="product-new-inner">            
            <div class="product-top-right"><div class="product-top-left"><div class="product-top-bg"></div></div></div>
            <div class="product-body">                    
                1. Tên sản phẩm <span style="font-size:8pt;color:Gray;font-weight:normal;">(<em>Vui lòng dùng tiếng Việt có dấu hoặc tiếng Anh, độ dài 40 ký tự</em>)</span>

            </div>
            <div class="product-bottom-right"><div class="product-bottom-left"><div class="product-bottom-bg"></div></div></div>
            <div class="product-new-control" style="margin-left:0px;text-align:center;margin-bottom:5px;">
                <input class="product-input-text" type="text" style="padding:3px;" id="t_tieude" name="t_tieude" value=""/>
            </div>
            <div style="margin-left:0px;text-align:left;margin-bottom:5px;margin-left:80px;margin-top:10px;font-size:10pt;">                
                <span class="notes" style="color:#666666;font-size:8pt;">
                    Mô tả ngắn :
                </span>
            </div>

            <div style="text-align:left;font-size:10pt;margin-bottom:10px;margin-left:80px;">  
                <input class="product-input-text2" type="text" id="t_mota" name="t_mota" value=""/>
            </div>      
            <div class="product-top-right"><div class="product-top-left"><div class="product-top-bg"></div></div></div>
            <div class="product-body">                    
                2. Chọn ngành hàng
            </div>
            <div class="product-bottom-right"><div class="product-bottom-left"><div class="product-bottom-bg"></div></div></div>
            <div class="product-new-control" style="margin-left:0px;text-align:center">                            
                <select style="margin:0" class="product-input-select" name="t_loaisanpham" id="t_loaisanpham">           
                    <option value=""></option>
				<?
					$rs = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_hienthi = 1 AND c_id_cha = 0");
					while($row = $db->fetch_array($rs)){
					$c_ten = $myString->unQuote(stripslashes($row[c_ten]));
					$c_id = $row[c_id];
				?>	
                    <optgroup label="<?=$c_ten?>">
					<?
						$rs2 = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_hienthi = 1 AND c_id_cha = '".$c_id."'");
						while($row2 = $db->fetch_array($rs2)){
						$c_id2 = $row2[c_id];
						$c_ten2 = $row2[c_ten];
					?>
						<option value="<?=$c_id2?>"><?=$c_ten2?></option>
					<? } ?>
					</optgroup>
				<? } ?>
                </select>
            </div>
            
            <div class="product-top-right"><div class="product-top-left"><div class="product-top-bg"></div></div></div>
            <div class="product-body">                    
                3. Mô tả sản phẩm 
            </div>
            <div class="product-bottom-right"><div class="product-bottom-left"><div class="product-bottom-bg"></div></div></div>
            <div class="product-new-control">            
                <div style="margin-left:50px;">  
					<p>
						<label class="title">Hàng khuyến mại</label>
						<span>
						<input type="radio" name="t_khuyenmai" value="0" checked="checked"/> Không
						<input type="radio" name="t_khuyenmai" value="1" /> Có
						</span>
					</p>
					<p>
						<label class="title">Hàng nổi bật</label>
						<span>
						<input type="radio" name="t_noibat" value="0" checked="checked"/> Không
						<input type="radio" name="t_noibat" value="1" /> Có
						</span>
					</p> 
					<p>
						<label class="title">Sắp ra mắt</label>
						<span>
						<input type="radio" name="t_sapramat" value="0" checked="checked"/> Không
						<input type="radio" name="t_sapramat" value="1" /> Có
						</span>
					</p>                  
                    <p>
                        <label class="title">Hình sản phẩm</label>

                        <span id="fileDiv">
                            <input name="t_hinhanh" id="t_hinhanh" type="file" class="file" accept="image/gif, image/jpeg, image/jpg" size="73" /><br />                            
                        </span>
                    </p>
                    <p>

                        <label class="title">&nbsp;</label>
                        <span class="notes" style="color:#666666;font-size:0.8em;">
                            Hỗ trợ file hình định dạng *.jpg, *.gif, *.png. Dung lượng file hình tối đa 1Mb.
                        </span>
                        <br class="clearBoth"/> 
                    </p>                    
                    <p>
                        <label class="title">Giá bán</label>
						<input type="text" name="t_giaban" id="t_giaban"  value="0" class="product-input-text txt-ie-fixed" style="float:left;width:145px;"/>
						<select name="t_loaitien" id="t_loaitien" class="product-input-select2" style="width:79px;margin-left:2px;">
						<?
							for($i=0;$i<count($arrLoaiTien);$i++){
						?>
						<option value="<?=$i?>"> <?=$arrLoaiTien[$i]?></option>
						<? } ?>
						</select>

                    </p>
					
					<p>
                        <label class="title">Giá thị trường</label>
						<input type="text" name="t_giathitruong" id="t_giathitruong"  value="0" class="product-input-text txt-ie-fixed" style="float:left;width:145px;"/>
						<select name="t_loaitien_giathitruong" id="t_loaitien_giathitruong" class="product-input-select2" style="width:79px;margin-left:2px;">
						<?
							for($i=0;$i<count($arrLoaiTien);$i++){
						?>
						<option value="<?=$i?>"> <?=$arrLoaiTien[$i]?></option>
						<? } ?>
						</select>

                    </p>
					
                    <p>
                        <label class="title">Quốc gia</label>
						
					<select id="txtQuocGia" name="txtQuocGia" style="width:100px;" onchange="ajaxSelect2Select('txtQuocGia','txtTinhThanh','<?=$root?>/loadTinhThanh.php','IdQuocGia');"> 
					<option value="-1">---Chọn---</option>
					<? 
						$rs = $db->query("SELECT * FROM ".$prefix."quocgia order by qg_id ASC");
						while($row = $db->fetch_array($rs)){
					?>
						<option value="<?=$row[qg_id]?>"><?=$row[qg_ten]?></option>
					<? } ?>
					</select>
					
					<label class="labelLine">Tỉnh/TP</label>
			        <select id="txtTinhThanh" name="txtTinhThanh">
						<option value="-1">---Chọn---</option>

						  <?
			
						  if($IdQuocGia) 
			
						  {
			
							$sql="select * from ".$prefix."tinhthanh where tt_maquocgia = '".$IdQuocGia."' order by tt_id ASC";
							$rs = $db->query($sql);
			
							if($db->num_rows($rs))
			
							{
			
								while($rows=$db->fetch_array($rs))
			
								{
			
								?>
			
								<option value="<?=$rows["tt_id"]?>"><?=$rows["tt_ten"]?></option>
			
								<?
			
								}
			
							}
			
						}
			
					?>

					</select>

                    </p>
					
                    <div>
                        <label class="title" id="lblSellingMethodID">Cách bán hàng</label>
                        <ul style="float:left;width:550px">
						<?
							for($i=0;$i<count($arrPhuongThucBanHang);$i++){
						?>
                            <li><input type="radio" name="chkPhuongThucBan" value="<?=$i?>" id="chkPhuongThucBan"<? if($i==0){?> checked="checked" <? }?> /><label><?=$arrPhuongThucBanHang[$i]?></label></li>
						<? } ?>	
							
                        </ul>

                    </div>   
					               
                </div>   
				               
            </div>  
            <br class="clearBoth"/>  
            <div style="height:15px;font-size:0px;"></div>      
            <div class="product-top-right"><div class="product-top-left"><div class="product-top-bg"></div></div></div>
            <div class="product-body">                    
                4. Chi tiết sản phẩm <span style="font-size:8pt;color:Gray;font-weight:normal;">(<em>Vui lòng dùng tiếng Việt có dấu hoặc tiếng Anh</em>)</span>
            </div>
            <div class="product-bottom-right"><div class="product-bottom-left"><div class="product-bottom-bg"></div></div></div>        
            <div class="product-new-control" style="margin-left:80px;">

                <textarea style="width:80%; height:400px; margin:0 auto;" rows="20" id="elm2" name="t_chitiet"></textarea>
            </div>
            <div class="product-new-control" style="width:650px;text-align:justify;margin-left:83px;">
                <input id="chkVND" type="checkbox" onclick="CheckVND()"/><label style="padding-left:5px; color:#888888;">Tôi đồng ý chịu trách nhiệm với tất cả thông tin bao gồm từ ngữ, hình ảnh, quyền sử dụng hình ảnh và kinh doanh hợp pháp sản phẩm, đồng tiền yết giá như được khai báo ở tất cả khoản mục trên trang này cũng như chấp nhận các điều khoản quy định khác của Kenh24h.com.</label>
            </div>              
        </div>
        <div class="clearBoth" style="text-align:center">

            <input type="image" id="btnSave_off" name="btnSave_off" src="<?=$root?>/themes/images/home/btnDangbanoff.jpg" onclick="javascript:return false;"/>
            <input type="image" name="btnSave" onclick="javascript: return submitForm();" id="btnSave" src="<?=$root?>/themes/images/home/btnDangban.jpg" value="Đăng bán" style="display:none;"/>            
        </div>   
        <div style="color:#888888;font-size:10pt;">
            (*) Nên và không nên khi đăng bán, xem <a target="_blank" href="javascript:void(0);">tại đây</a>
        </div>
    </div>
    <div class="corner-round-02-bottom-right">
        <div class="corner-round-02-bottom-left">

            <div class="corner-round-02-bottom-bg"></div>
        </div>
    </div>   
</div>
<div style="height:10px"> </div>
<div id="uploadDiv"></div>       
    </div>
    <div style="clear:both;"></div>      
    <!-- } Main Page-Content -->  
	<input type="hidden" name="submit" id="submit" value="submit" />
</form>
                
</div>
